package com.zzedu.service.impl;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.zzedu.common.enums.CommonEnums;
import com.zzedu.common.utils.StringUtils;
import com.zzedu.common.utils.bean.BeanUtils;
import com.zzedu.common.utils.file.FileUtils;
import com.zzedu.common.utils.uuid.IdUtils;
import com.zzedu.domain.*;
import com.zzedu.dto.ZzThesaurusWordsDTO;
import com.zzedu.enmuns.FileRelationTypeEnum;
import com.zzedu.enmuns.WordsAttrEnum;
import com.zzedu.integration.oss.IOssClientService;
import com.zzedu.integration.oss.dto.FileInfoDTO;
import com.zzedu.integration.oss.dto.OssFileResult;
import com.zzedu.mapper.ZzThesaurusWordsMapper;
import com.zzedu.params.SpeechAttrParams;
import com.zzedu.params.UploadWordFileParams;
import com.zzedu.params.ZzThesaurusWordsAllParams;
import com.zzedu.service.*;
import com.zzedu.vo.ZzThesaurusWordsVO;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.token.Sha512DigestUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * 单词管理Service业务层处理
 *
 * @author Mr.Wang
 * @date 2025-01-29
 */
@Service
public class ZzThesaurusWordsServiceImpl extends ServiceImpl<ZzThesaurusWordsMapper, ZzThesaurusWords> implements IZzThesaurusWordsService {

    /**
     * 单词标签
     */
    @Autowired
    IZzThesaurusWordsTagRelatedService zzThesaurusWordsTagRelatedService;

    @Autowired
    IZzThesaurusTagService zzThesaurusTagService;
    /**
     * 单词属性
     */
    @Autowired
    IZzThesaurusAttrService zzThesaurusAttrService;

    @Autowired
    IZzUploadFileService zzUploadFileService;

    @Autowired
    IOssClientService ossClientService;


    @Override
    public LambdaQueryWrapper<ZzThesaurusWords> buildQuery(ZzThesaurusWordsDTO zzThesaurusWords) {
        LambdaQueryWrapper<ZzThesaurusWords> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.like(StringUtils.isNotBlank(zzThesaurusWords.getWord()), ZzThesaurusWords::getWord, zzThesaurusWords.getWord());
        lambdaQueryWrapper.eq(null != zzThesaurusWords.getOnLineFlag(), ZzThesaurusWords::getOnLineFlag, zzThesaurusWords.getOnLineFlag());
        lambdaQueryWrapper.eq(null != zzThesaurusWords.getWordType(), ZzThesaurusWords::getWordType, zzThesaurusWords.getWordType());
        lambdaQueryWrapper.apply(null != zzThesaurusWords.getIncludeContentId(), "id in(select relation_id from zz_course_content_relate where relation_type=1 and content_id={0})", zzThesaurusWords.getIncludeContentId());
        lambdaQueryWrapper.apply(null != zzThesaurusWords.getExcludeContentId(), "id not in(select relation_id from zz_course_content_relate where relation_type=1 and content_id={0})", zzThesaurusWords.getExcludeContentId());
        // (select word_id from zz_thesaurus_words_tag_related where deleted=0 and tag_id in(select relation_id from zz_course_content_relate where relation_type=2 and content_id={0}) and tag_id in(select id from zz_thesaurus_tag where deleted=0))
        lambdaQueryWrapper.apply(null != zzThesaurusWords.getIncludeContentIdTag(), "id in(select word_id from zz_thesaurus_words_tag_related where deleted=0 and tag_id in(select relation_id from zz_course_content_relate where relation_type=2 and content_id={0}) and tag_id in(select id from zz_thesaurus_tag where deleted=0))", zzThesaurusWords.getIncludeContentIdTag());
        lambdaQueryWrapper.orderByDesc(ZzThesaurusWords::getId);
        return lambdaQueryWrapper;
    }

    @Override
    public List<ZzThesaurusWordsVO> convertVO(List<ZzThesaurusWords> zzThesaurusWordsList) {
        if (CollectionUtils.isEmpty(zzThesaurusWordsList)) {
            return Lists.newArrayList();
        }
        List<ZzThesaurusAttr> zzThesaurusAttrList = Optional.ofNullable(zzThesaurusAttrService.list(Wrappers.lambdaQuery(ZzThesaurusAttr.class).select(ZzThesaurusAttr::getId, ZzThesaurusAttr::getWordId, ZzThesaurusAttr::getAttrValue).in(ZzThesaurusAttr::getWordId, zzThesaurusWordsList.stream().map(ZzThesaurusWords::getId).collect(Collectors.toList())).eq(ZzThesaurusAttr::getAttrCode, WordsAttrEnum.wordAttr.getCode()))).orElse(Lists.newArrayList());


        return Optional.ofNullable(zzThesaurusWordsList).orElse(Lists.newArrayList()).stream().map(zzThesaurusWords -> {
            ZzThesaurusWordsVO zzThesaurusWordsVO = new ZzThesaurusWordsVO();
            BeanUtils.copyBeanProp(zzThesaurusWordsVO, zzThesaurusWords);
            if (1 == zzThesaurusWords.getWordType()) {
                String word = zzThesaurusWords.getWord();
                char[] wordChar = word.toUpperCase().toCharArray();
                List<String> letter = Lists.newArrayList();
                for (char c : wordChar) {
                    letter.add(c + String.valueOf(c).toLowerCase());
                }
                zzThesaurusWordsVO.setLetter(Joiner.on(" ").join(letter));
                zzThesaurusWordsVO.setSpeechTag(Lists.newArrayList());
                for (ZzThesaurusAttr zzThesaurusAttr : zzThesaurusAttrList) {
                    if (zzThesaurusAttr.getWordId().equals(zzThesaurusWords.getId())) {
                        JSONObject obj = new JSONObject();
                        WordsAttrEnum wordsAttrEnum = WordsAttrEnum.getCode(zzThesaurusAttr.getAttrValue());
                        obj.put("id", zzThesaurusAttr.getId());
                        obj.put("text", wordsAttrEnum.getDesc());
                        zzThesaurusWordsVO.getSpeechTag().add(obj);
                    }
                }
                //音频数量
                zzThesaurusWordsVO.setAudioCount(this.zzThesaurusAttrService.count(Wrappers.lambdaQuery(ZzThesaurusAttr.class).eq(ZzThesaurusAttr::getWordId, zzThesaurusWords.getId()).eq(ZzThesaurusAttr::getAttrCode, WordsAttrEnum.audio.getCode())));
                //图片
                zzThesaurusWordsVO.setImageCount(this.zzThesaurusAttrService.count(Wrappers.lambdaQuery(ZzThesaurusAttr.class).eq(ZzThesaurusAttr::getWordId, zzThesaurusWords.getId()).in(ZzThesaurusAttr::getAttrCode, IZzThesaurusAttrService.imageAttrCodeList)));
            }
            return zzThesaurusWordsVO;
        }).collect(Collectors.toList());
    }

    public ZzThesaurusWordsAllParams getFormById(Long id) {
        ZzThesaurusWords zzThesaurusWords = getById(id);
        Assert.isTrue(null != zzThesaurusWords, "单词不存在");
        //所有的属性
        List<ZzThesaurusAttr> zzThesaurusAttrList = zzThesaurusAttrService.list(Wrappers.lambdaQuery(ZzThesaurusAttr.class).eq(ZzThesaurusAttr::getWordId, id));
        ZzThesaurusWordsAllParams zzThesaurusWordsAllParams = null;
        List<SpeechAttrParams> speechList = Lists.newArrayList();
        if (CollectionUtils.isNotEmpty(zzThesaurusAttrList)) {
            JSONObject attrJSON = new JSONObject();
            for (ZzThesaurusAttr zzThesaurusAttr : zzThesaurusAttrList) {
                if (WordsAttrEnum.wordAttr != WordsAttrEnum.getCode(zzThesaurusAttr.getAttrCode())) {
                    continue;
                }
                if (StringUtils.isNotBlank(zzThesaurusAttr.getAttrExtend()) && JSON.isValidObject(zzThesaurusAttr.getAttrExtend())) {
                    JSONObject extendJSON = JSON.parseObject(zzThesaurusAttr.getAttrExtend());
                    attrJSON.putAll(extendJSON);
                }
                String attrValue = zzThesaurusAttr.getAttrValue();
                WordsAttrEnum wordsAttrEnum = WordsAttrEnum.getCode(attrValue);
                SpeechAttrParams speechAttrParams = new SpeechAttrParams();
                speechAttrParams.setCode(wordsAttrEnum.name());
                speechAttrParams.setText(wordsAttrEnum.getDesc());
                speechList.add(speechAttrParams);
            }
            zzThesaurusWordsAllParams = JSON.parseObject(attrJSON.toJSONString(), ZzThesaurusWordsAllParams.class);
            AtomicInteger audioAtomicLong = new AtomicInteger(0);
            //图片
            zzThesaurusWordsAllParams.setUploadWordFileParams(Optional.ofNullable(zzThesaurusAttrList).orElse(Lists.newArrayList()).stream().filter(zzThesaurusAttr -> zzThesaurusAttr.getAttrCode().contains("_" + WordsAttrEnum.image.getCode())).map(zzThesaurusAttr -> {
                String attrCode = zzThesaurusAttr.getAttrCode();
                UploadWordFileParams uploadFileParam = new UploadWordFileParams();
                ZzUploadFile zzUploadFile = zzUploadFileService.getById(zzThesaurusAttr.getAttrValue());
                uploadFileParam.setUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                uploadFileParam.setSortNum(audioAtomicLong.incrementAndGet());
                uploadFileParam.setId(zzThesaurusAttr.getId());
                uploadFileParam.setExtendKey(attrCode.split("\\_")[0]);
                return uploadFileParam;
            }).collect(Collectors.toList()));
            //音频文件
            zzThesaurusWordsAllParams.setAudioFileList(Optional.ofNullable(zzThesaurusAttrList).orElse(Lists.newArrayList()).stream().filter(zzThesaurusAttr -> zzThesaurusAttr.getAttrCode().equals(WordsAttrEnum.audio.getCode())).map(zzThesaurusAttr -> {
                String attrCode = zzThesaurusAttr.getAttrCode();
                UploadWordFileParams uploadFileParam = new UploadWordFileParams();
                ZzUploadFile zzUploadFile = zzUploadFileService.getById(zzThesaurusAttr.getAttrValue());
                uploadFileParam.setUrl(ossClientService.convertURL(zzUploadFile.getUrl()));
                uploadFileParam.setSortNum(audioAtomicLong.incrementAndGet());
                uploadFileParam.setId(zzThesaurusAttr.getId());
                return uploadFileParam;
            }).collect(Collectors.toList()));
        }
        if (null == zzThesaurusWordsAllParams) {
            zzThesaurusWordsAllParams = new ZzThesaurusWordsAllParams();
            zzThesaurusWordsAllParams.setAudioFileList(Lists.newArrayList());
        }
        zzThesaurusWordsAllParams.setId(id);
        zzThesaurusWordsAllParams.setWord(zzThesaurusWords.getWord());
        zzThesaurusWordsAllParams.setSpeechList(speechList);

        List<ZzThesaurusWordsTagRelated> zzThesaurusWordsTagRelatedList = this.zzThesaurusWordsTagRelatedService.list(Wrappers.lambdaQuery(ZzThesaurusWordsTagRelated.class).eq(ZzThesaurusWordsTagRelated::getWordId, id));
        zzThesaurusWordsAllParams.setTag(Lists.newArrayList());
        if (CollectionUtils.isNotEmpty(zzThesaurusWordsTagRelatedList)) {
            List<ZzThesaurusTag> zzThesaurusTagList = this.zzThesaurusTagService.list(Wrappers.lambdaQuery(ZzThesaurusTag.class).in(ZzThesaurusTag::getId, zzThesaurusWordsTagRelatedList.stream().map(ZzThesaurusWordsTagRelated::getTagId).collect(Collectors.toList())));
            zzThesaurusWordsAllParams.setTag(Optional.ofNullable(zzThesaurusTagList).orElse(Lists.newArrayList()).stream().map(ZzThesaurusTag::getTagName).collect(Collectors.toList()));
        }
        return zzThesaurusWordsAllParams;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteAttrData(Long id) {
        ZzThesaurusAttr wordAttrData = this.zzThesaurusAttrService.getById(id);
        if (null != wordAttrData) {
            zzThesaurusAttrService.remove(Wrappers.lambdaQuery(ZzThesaurusAttr.class).eq(ZzThesaurusAttr::getWordId, wordAttrData.getWordId()).eq(ZzThesaurusAttr::getAttrCode, wordAttrData.getAttrValue() + "_" + WordsAttrEnum.image.getCode()));
        }
        zzThesaurusAttrService.removeById(id);
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean allSaveWords(ZzThesaurusWordsAllParams zzThesaurusWordsParams) throws Exception {
        ZzThesaurusWords zzThesaurusWords = new ZzThesaurusWords();
        zzThesaurusWords.setWordType(1);
        BeanUtils.copyBeanProp(zzThesaurusWords, zzThesaurusWordsParams);
        zzThesaurusWords.setOnLineFlag(CommonEnums.NO.getCode());
        if(null!=zzThesaurusWords.getId()){
            zzThesaurusWords.setOnLineFlag(null);
        }
        String planText = zzThesaurusWordsParams.getWord();
        planText = zzThesaurusWords.getWordType() + ":" + planText.replaceAll("\\s+", "");
        planText = planText.toUpperCase();
        String keyData = Sha512DigestUtils.shaHex(planText);
        zzThesaurusWords.setKeyData(keyData);
        String initial = zzThesaurusWords.getWord().replaceAll("\\s+", "").substring(0, 1).toUpperCase();
        if (StringUtils.startsWithLetter(initial)) {
            zzThesaurusWords.setInitial(initial);
        }
        if(null!=zzThesaurusWords.getId()){
            zzThesaurusWords.setOnLineFlag(null);
        }
        boolean res = saveOrUpdate(zzThesaurusWords);
        //标签处理
        if (CollectionUtils.isNotEmpty(zzThesaurusWordsParams.getTag())) {
            if (null != zzThesaurusWordsParams.getId()) {
                zzThesaurusWordsTagRelatedService.remove(Wrappers.lambdaQuery(ZzThesaurusWordsTagRelated.class).eq(ZzThesaurusWordsTagRelated::getWordId, zzThesaurusWordsParams.getId()));
            }
            for (String tag : zzThesaurusWordsParams.getTag()) {
                ZzThesaurusTag zzThesaurusTag = null;
                if ((zzThesaurusTag = zzThesaurusTagService.getOne(Wrappers.lambdaQuery(ZzThesaurusTag.class).eq(ZzThesaurusTag::getTagName, tag).last("limit 1"))) == null) {
                    zzThesaurusTag = new ZzThesaurusTag();
                    zzThesaurusTag.setTagName(tag);
                    zzThesaurusTagService.save(zzThesaurusTag);
                }
                ZzThesaurusWordsTagRelated zzThesaurusWordsTagRelated = new ZzThesaurusWordsTagRelated();
                zzThesaurusWordsTagRelated.setWordId(zzThesaurusWords.getId());
                zzThesaurusWordsTagRelated.setTagId(zzThesaurusTag.getId());
                zzThesaurusWordsTagRelatedService.save(zzThesaurusWordsTagRelated);
            }
        }
        //图片处理
        List<UploadWordFileParams> uploadWordFileParams = zzThesaurusWordsParams.getUploadWordFileParams();
        List<Long> notDeleteIds = Lists.newArrayList();
        if (CollectionUtils.isNotEmpty(uploadWordFileParams)) {
            uploadWordFileParams = Optional.ofNullable(uploadWordFileParams).orElse(Lists.newArrayList()).stream().sorted(Comparator.comparing(UploadWordFileParams::getSortNum, Comparator.nullsLast(Comparator.naturalOrder()) // 将 null 排在最后
            )).collect(Collectors.toList());
            FileRelationTypeEnum fileRelationTypeEnum = FileRelationTypeEnum.WORD;
            for (UploadWordFileParams fileParams : uploadWordFileParams) {
                if (fileParams.getFile() != null) {
                    OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(fileParams.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), fileParams.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                    if (fileUploadResult.isSuccess()) {
                        FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                        ZzUploadFile uploadFile = new ZzUploadFile();
                        uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                        uploadFile.setUrl(fileInfoDTO.getUrl());
                        uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                        uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                        uploadFile.setRelationId(String.valueOf(zzThesaurusWords.getId()));
                        uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                        uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                        uploadFile.setSize(fileInfoDTO.getSize());
                        uploadFile.setSortNum(uploadFile.getId());
                        zzUploadFileService.save(uploadFile);
                        //写入属性
                        String attrCode = fileParams.getExtendKey() + "_" + WordsAttrEnum.image.getCode();
                        ZzThesaurusAttr zzThesaurusAttr = new ZzThesaurusAttr();
                        zzThesaurusAttr.setWordId(zzThesaurusWords.getId());
                        zzThesaurusAttr.setAttrCode(attrCode);
                        zzThesaurusAttr.setAttrName(WordsAttrEnum.image.getDesc());
                        zzThesaurusAttr.setAttrValue(String.valueOf(uploadFile.getId()));
                        this.zzThesaurusAttrService.save(zzThesaurusAttr);
                        notDeleteIds.add(zzThesaurusAttr.getId());
                    }
                } else {
                    notDeleteIds.add(fileParams.getId());
                }
            }
        }
        //录音文件处理
        uploadWordFileParams = zzThesaurusWordsParams.getAudioFileList();
        if (CollectionUtils.isNotEmpty(uploadWordFileParams)) {
            uploadWordFileParams = Optional.ofNullable(uploadWordFileParams).orElse(Lists.newArrayList()).stream().sorted(Comparator.comparing(UploadWordFileParams::getSortNum, Comparator.nullsLast(Comparator.naturalOrder()) // 将 null 排在最后
            )).collect(Collectors.toList());
            FileRelationTypeEnum fileRelationTypeEnum = FileRelationTypeEnum.WORD;
            for (UploadWordFileParams fileParams : uploadWordFileParams) {
                if (fileParams.getFile() != null) {
                    OssFileResult<FileInfoDTO> fileUploadResult = ossClientService.uploadFile(fileParams.getFile().getBytes(), fileRelationTypeEnum.getOssPath(), fileParams.getFile().getOriginalFilename(), IdUtils.fastSimpleUUID());
                    if (fileUploadResult.isSuccess()) {
                        FileInfoDTO fileInfoDTO = fileUploadResult.getData();
                        ZzUploadFile uploadFile = new ZzUploadFile();
                        uploadFile.setRelationType(fileRelationTypeEnum.getCode());
                        uploadFile.setUrl(fileInfoDTO.getUrl());
                        uploadFile.setOldFileName(fileInfoDTO.getOriginalFilename());
                        uploadFile.setFileName(FileUtils.getName(fileInfoDTO.getNewFileName()));
                        uploadFile.setRelationId(String.valueOf(zzThesaurusWords.getId()));
                        uploadFile.setFileExt(fileInfoDTO.getFileSuffix());
                        uploadFile.setSourceModel(fileRelationTypeEnum.getCode());
                        uploadFile.setSize(fileInfoDTO.getSize());
                        uploadFile.setSortNum(uploadFile.getId());
                        zzUploadFileService.save(uploadFile);
                        ZzThesaurusAttr zzThesaurusAttr = new ZzThesaurusAttr();
                        zzThesaurusAttr.setWordId(zzThesaurusWords.getId());
                        zzThesaurusAttr.setAttrCode(WordsAttrEnum.audio.getCode());
                        zzThesaurusAttr.setAttrName(WordsAttrEnum.audio.getDesc());
                        zzThesaurusAttr.setAttrValue(String.valueOf(uploadFile.getId()));
                        this.zzThesaurusAttrService.save(zzThesaurusAttr);
                        notDeleteIds.add(zzThesaurusAttr.getId());
                    }
                } else {
                    notDeleteIds.add(fileParams.getId());
                }
            }
        }
        if (CollectionUtils.isNotEmpty(notDeleteIds)) {
            //干掉所有属性
            zzThesaurusAttrService.remove(Wrappers.lambdaQuery(ZzThesaurusAttr.class).eq(ZzThesaurusAttr::getWordId, zzThesaurusWords.getId()).notIn(ZzThesaurusAttr::getId, notDeleteIds));
        } else {
            //干掉所有属性
            zzThesaurusAttrService.remove(Wrappers.lambdaQuery(ZzThesaurusAttr.class).eq(ZzThesaurusAttr::getWordId, zzThesaurusWords.getId()));
        }
        if (CollectionUtils.isNotEmpty(zzThesaurusWordsParams.getSpeechList())) {

            for (SpeechAttrParams speechAttrParams : zzThesaurusWordsParams.getSpeechList()) {
                WordsAttrEnum wordsAttrEnum = WordsAttrEnum.valueOf(speechAttrParams.getCode());
                //写入其他属性值
                ZzThesaurusAttr zzThesaurusAttr = new ZzThesaurusAttr();
                zzThesaurusAttr.setAttrName(WordsAttrEnum.wordAttr.getDesc());
                zzThesaurusAttr.setAttrCode(WordsAttrEnum.wordAttr.getCode());
                zzThesaurusAttr.setAttrValue(wordsAttrEnum.getCode());
                zzThesaurusAttr.setWordId(zzThesaurusWords.getId());
                JSONObject attrExtend = new JSONObject();
                if (WordsAttrEnum.Noun == wordsAttrEnum) {
                    attrExtend.put("complexNumber_Text", "复数");
                    attrExtend.put("complexNumber", zzThesaurusWordsParams.getComplexNumber());
                } else if (WordsAttrEnum.Adjective == wordsAttrEnum) {
                    //形容词
                    attrExtend.put("adjectiveComparative_Text", "比较级");
                    attrExtend.put("adjectiveComparative", zzThesaurusWordsParams.getAdjectiveComparative());
                    attrExtend.put("adjectiveSuperlative_Text", "最高级");
                    attrExtend.put("adjectiveSuperlative", zzThesaurusWordsParams.getAdjectiveSuperlative());
                } else if (WordsAttrEnum.Adverb == wordsAttrEnum) {
                    //副词
                    attrExtend.put("adverbComparative_Text", "比较级");
                    attrExtend.put("adverbComparative", zzThesaurusWordsParams.getAdverbComparative());
                    attrExtend.put("adverbSuperlative_Text", "最高级");
                    attrExtend.put("adverbSuperlative", zzThesaurusWordsParams.getAdverbSuperlative());
                } else if (WordsAttrEnum.Verb == wordsAttrEnum) {
                    attrExtend.put("pastParticiple_Text", "过去分词");
                    attrExtend.put("pastParticiple", zzThesaurusWordsParams.getPastParticiple());
                    attrExtend.put("presentParticiple_Text", "现在分词");
                    attrExtend.put("presentParticiple", zzThesaurusWordsParams.getPresentParticiple());
                    attrExtend.put("thirdPersonSingular_Text", "第三人称单数");
                    attrExtend.put("thirdPersonSingular", zzThesaurusWordsParams.getThirdPersonSingular());
                } else if (WordsAttrEnum.Pronoun == wordsAttrEnum) {
                    attrExtend.put("nominative_Text", "主格");
                    attrExtend.put("nominative", zzThesaurusWordsParams.getNominative());
                    attrExtend.put("accusative_Text", "宾格");
                    attrExtend.put("accusative", zzThesaurusWordsParams.getAccusative());
                } else if (WordsAttrEnum.Numeral == wordsAttrEnum) {
                    attrExtend.put("cardinalNumber_Text", "基数词");
                    attrExtend.put("cardinalNumber", zzThesaurusWordsParams.getCardinalNumber());
                    attrExtend.put("ordinalNumber_Text", "序数词");
                    attrExtend.put("ordinalNumber", zzThesaurusWordsParams.getOrdinalNumber());
                }
                zzThesaurusAttr.setAttrExtend(attrExtend.toJSONString());
                zzThesaurusAttrService.save(zzThesaurusAttr);
            }
        }
        return true;
    }

    @Override
    public List<ZzThesaurusWords> getOnLineByIds(List<Long> ids) {
        return this.list(Wrappers.lambdaQuery(ZzThesaurusWords.class).in(ZzThesaurusWords::getId, ids));
    }
}